package br.unb.mestrado.simulator.ui.util;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;


public class UtilSimulator {

	public static Button createButton(Composite parent, String label, String tip, SelectionListener l) {
        Button b = new Button(parent, SWT.NONE);
        b.setText(label);
        if (tip != null) {
            b.setToolTipText(tip);
        }
        if (l != null) {
            b.addSelectionListener(l);
        }
        return b;
    }
	
	public static Text createAreaText(Composite parent, String label,
			int limit, String tip) {
		Label l = new Label(parent, SWT.LEFT);
		l.setText(label);
		Text text = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
		if (limit > 0) {
			text.setTextLimit(limit);
		}
		if (tip != null) {
			text.setToolTipText(tip);
		}
		text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		return text;
	}


	public static Text createText(Composite parent, String label,
			int limit, String tip) {
		Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
		if (limit > 0) {
			text.setTextLimit(limit);
		}
		if (tip != null) {
			text.setToolTipText(tip);
		}
		text.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
		return text;
	}
	
	public static Text createLabelledText(Composite parent, String label,
			int limit, String tip) {
		Label l = new Label(parent, SWT.LEFT);
		l.setText(label);
		Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
		if (limit > 0) {
			text.setTextLimit(limit);
		}
		if (tip != null) {
			text.setToolTipText(tip);
		}
		text.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
		return text;
	}

	public static Button createCheckbox(Composite parent, String label, String tip) {
		Button button = new Button (parent, SWT.CHECK);
		button.setText (label);
		button.setSelection(false);
		return button;
	}

}
